package com.naiterui.ehp.bs.file.enums;

import java.util.Arrays;

/**
 * 文件content-type枚举
 * 
 * @author yangfuya
 * @since 2021/9/10
 */
public enum FileEnum {
    /**
     * 图片相关
     */
    JPG("jpg", "image/jpg"), JPEG("jpeg", "image/jpeg"), PNG("png", "image/png"), JPE("jpe", "image/jpeg"),
    ICO("ico", "image/x-icon"), GIF("gif", "image/gif"),
    /**
     * 音视频相关
     */
    MP3("mp3", "audio/mp3"), MP4("mp4", "video/mp4"),
    /**
     * 文档相关
     */
    PDF("pdf", "application/pdf"), XLS("xls", "application/vnd.ms-excel"),
    XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

    /**
     * 文件类型名
     */
    private final String name;
    /**
     * 文件类型content-type值
     */
    private final String value;

    FileEnum(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public String getValue() {
        return value;
    }

    public static String getValueByName(String name) {
        return Arrays.stream(FileEnum.values()).filter(s -> s.getName().equals(name.toLowerCase())).findFirst().get()
            .getValue();
    }
}
